<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="h" uri="/syzg-html"%>
<%
	request.setAttribute("ctx", request.getContextPath());
%>
<!DOCTYPE html>
<html>
<head>
<script src="${ctx}/zenithsun/plugins/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
	var NewsSelectModalUrl = "${ctx}/zenithsun/news/specialnews/selectNews.jsp?snId=";
	var setNewsUrl = "${ctx}/path/specialnews/setNews?snId=${specialnews.id}";
	function showSelectNewsModal() {
		$("#myDlgSelectNews").load(NewsSelectModalUrl, function() {
			$("#selectNewsModal").modal("show");
		});
	}
	$(function(){
		  $("#crop_upload").click(function () {
		        $.ajaxFileUpload
		        (
		            {
		                url: "${ctx}/path/newsinfo/uploadCover?newId=", //用于文件上传的服务器端请求地址
		                secureuri: false, //一般设置为false
		                fileElementId: 'crop_upload_file', //文件上传空间的id属性  <input type="file" id="file" name="file" />
		                dataType: 'json', //返回值类型 一般设置为json
		                success: function (data, status)  //服务器成功响应处理函数
		                {
		                	var coverPath = data.content;
	                        $("#coverImage").attr("src","${ctx}"+coverPath);
	                        $("#coverPath").val(data.content);
		                },
		                error: function (data, status, e)//服务器响应失败处理函数
		                {
		                	bootbox.alert("上传失败");
		                }
		            }
		        )
		   });
		  
		  $("#newsList").load(setNewsUrl);
	  });
</script>
</head>
<body>
	<div class="modal fade bs-example-modal-lg" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog modal-lg" role="document" style="margin-top: 0">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改专题新闻</h4>
				</div>
				<div class="modal-body" id="modalCore">
					<form class="form-horizontal" role="form" id="aeForm" name="aeForm">
						<fieldset>
							<input type="hidden" name="id" value="${specialnews.id}" /> 
							<input type="hidden" id="selectedNews" name="selectedNews" /> 
							<div class="bs-example bs-example-tabs"	data-example-id="togglable-tabs">
								<ul id="myTabs" class="nav nav-tabs" role="tablist">
									<li role="presentation" class="active"><a href="#baseInfo2" role="tab" data-toggle="tab">新闻基本信息</a></li>
									<li role="presentation"><a href="#pics2" role="tab" data-toggle="tab">新闻列表</a></li>
								</ul>
								<div id="myTabContent" class="tab-content" style="height: 420px;">
									<div role="tabpanel" class="tab-pane fade in active" style="margin-top: 5px;" id="baseInfo2" aria-labelledBy="home-tab">
										<div class="form-group">
											<label class="col-sm-2 control-label" for="title">专题标题</label>
											<div class="col-sm-8">
												<input type="text" id="title" name="title" value="${specialnews.title}" class="form-control" />
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="isTop">新闻设置</label>
											<div class="col-sm-8">
												<label class="checkbox-inline"> 
													<input type="checkbox" id="isTop" name="isTop" value="0" onclick="this.value=this.checked?1:0"> 主题置顶
												</label>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="title">专题封面</label>
											<div class="col-sm-8">
												<input type="hidden" name="coverPath" id="coverPath" value="${specialnews.coverPath}">
												<img width="100%" height="300" id="coverImage" src="${ctx}${specialnews.coverPath}">
											</div>
										</div>
										<div >
											<div style="float: right;">
												<input type="file" id="crop_upload_file" name="file" accept="image/*" />
											</div>
											<div style="float: right;">
												<button type="button" class="btn btn-primary" id="crop_upload">确认上传图片</button>
											</div>
										</div>
									</div>
									<div role="tabpanel" class="tab-pane fade" style="margin-top: 5px;" id="pics2" aria-labelledBy="profile-tab">
										<table width="100%" class="title" border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td align="right">
													<h:permission module="xxx_xxx" operation="add">
														<button type="button" class="btn btn-primary btn-sm" onclick="showSelectNewsModal()">添加新闻</button>
													</h:permission>
												</td>
											</tr>
										</table>
										<div id="newsList" style="overflow: auto;height:380px;">
											
										</div>
									</div>
								</div>
							</div>
						</fieldset>
					</form>
				</div>
				
				<div id="myDlgSelectNews"></div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" onclick="submitSave('edit');">保存</button>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		
		$('#aeForm').bootstrapValidator({
			message : 'This value is not valid',
			feedbackIcons : {
				valid : 'glyphicon glyphicon-ok',
				invalid : 'glyphicon glyphicon-remove',
				validating : 'glyphicon glyphicon-refresh'
			},
			fields : {
			/*name: {
			  group: '.col-sm-3',
			    message: 'The username is not valid',
			    validators: {
			        notEmpty: {
			            message: 'The username is required and cannot be empty'
			        },
			        stringLength: {
			            min: 6,
			            max: 30,
			            message: 'The username must be more than 6 and less than 30 characters long'
			        }
			    }
			},
			email: {
			  group: '.col-sm-3',
			    validators: {
			        emailAddress: {
			            message: 'The input is not a valid email address'
			        }
			    }
			}*/
			}
		}).on('success.form.bv', function(e, data) {
			var ids = "";
			$("input:hidden[name='selectedNewsId']").each(function(){
				ids += $(this).val() +",";
			});
			ids = ids.substring(0,ids.length - 1);
			$("#selectedNews").val(ids);
			FormFunction.submitSave('edit');
		});
	</script>
</body>
</html>